// 函数定义方式一:
function abs(x) {
    if (isNaN(x)) {
        throw "is not a number!"
    }
    if (x < 0) {
        return -x
    } else {
        return x
    }
}

// 函数定义方式二:
let abs2 = function (x) {
    if (isNaN(x)) {
        throw "is not a number!"
    }
    if (x < 0) {
        return -x
    } else {
        return x
    }
};

console.log(abs(-10));
console.log(abs2("10"));

/* ----------------argument----------------- */
// arguments代表所有传递进来的参数, 是一个数组
function test(person) {
    for (let argument of arguments) {
        console.log(argument)
    }
    console.log(`hello ${person}`)
}

test("xiaobai", "xiaohei");

// ES6新特性reset
function sum(a, b, ...reset) {
    let sum = a + b;
    for (let x of reset) {
        sum += x;
    }
    return sum;
}

console.log(sum(1, 2, 3, 4, 5));

